package timing.ukulele.portal.dictionary;

import timing.ukulele.common.dictionary.CodeDescriptionEnum;

import java.util.Arrays;

public enum MenuType implements CodeDescriptionEnum {
    WEB(0, "网页"),
    UNIAPP(5, "跨平台(uniapp)"),
    FLUTTER(10, "跨平台(flutter)"),
    ANDROID(15, "安卓客户端"),
    IOS(20, "苹果客户端"),
    ANDROID_PAD(25, "安卓平板"),
    IOS_PAD(30, "苹果PAD"),
    WECHAT_APP(35, "微信小程序"),
    WECHAT_MP(40, "微信公众号"),
    WINDOW(45, "windows客户端"),
    MAC(50, "MAC客户端");

    private Integer code;
    private String description;

    MenuType(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public static String getDescriptionByCode(Integer code) {
        if (code == null)
            return "未知";
        for (MenuType typeEnum : values()) {
            if (typeEnum.code.equals(code)) {
                return typeEnum.description;
            }
        }
        return "未知";
    }

    public static Boolean hasValue(Integer code) {
        long count = Arrays.stream(values()).filter(item -> item.code.equals(code)).count();
        return count > 0;
    }

    @Override
    public String toString() {
        return code + "";
    }

    @Override
    public Integer getCode() {
        return this.code;
    }

    @Override
    public String getDescription() {
        return this.description;
    }
}
